#include "FadeOutState.h"
#include "Portfolio.h"

FadeOutState::FadeOutState(void)
{
}

FadeOutState::~FadeOutState(void)
{
}

void FadeOutState::enter()
{	
	alphaLevel = 0;
	// save the back buffer image to another layer
	port->getGUtil()->drawToBackBuffer(port->getGUtil()->getLevel(0), 0, 0, 1);
	port->getGUtil()->clearBufferToColor(0, 0, 0, 2); // black image to level 2
}

void FadeOutState::update(const float delta)
{
	const float fadeSpeed = 10.0f;
	alphaLevel = alphaLevel + (fadeSpeed * delta);
	if (static_cast<int>(alphaLevel) > 250)
	{
		port->exitRenderLoop();
		alphaLevel = 250;
	}
}

void FadeOutState::render()
{
	port->getGUtil()->fader(
		port->getGUtil()->getLevel(2),
		port->getGUtil()->getLevel(1),
		static_cast<int>(alphaLevel));
	port->getGUtil()->drawBackBufferToScreen();
}

void FadeOutState::leave()
{
	alphaLevel = 0;
}